/*
 rdlg.js

 (used with rdlg.css, images used in rdlg.css)
  
 * Simplely designed popup dialog.
 *
 * Inspired and based on Prototype, Scriptaculous and popup libraray
    Prototype library: http://www.prototypejs.org/
    Scriptaculous library: http://script.aculo.us/
    Popup library: http;//www.methods.co.nz/popup/popup.html
 *
 * Version 0.1
 * 
 * Author: Kim, Jung Hyun (mail@ikspres.com)
 * License: This source code is released under MIT license.
 * Copyright (c) Kim, Jung Hyun 2007
 *

Usage
====================

// This is an sample html using rdlg

<head>

// Yes!, you need prototype and scriptaculou at first.

   <script src="/javascripts/prototype.js?1183015069" type="text/javascript"></script>
   <script src="/javascripts/effects.js?1183015069" type="text/javascript"></script>
   <script src="/javascripts/dragdrop.js?1183015069" type="text/javascript"></script>
   <script src="/javascripts/controls.js?1183015069" type="text/javascript"></script>


// and popup

   <script src="/javascripts/popup.js" type="text/javascript"></script>


// and rdlg too.

   <script src="/javascripts/popup.js" type="text/javascript"></script>
   <link href="/stylesheets/rdlg.css" media="screen" rel="Stylesheet" type="text/css" />

</head>



// You may need an trigger to open your rdlg

<button id='opener'> click me to open dialog</button>


// and write your contents into the following format

<div id='my_dialog' class='rdlg' style='display:none'>
  <div class='rdlg-content'>
    //put your own contents here
  </div>
  <div class='rdlg-body-buttons'>
    // put your buttons here 
  </div>
</div>


// or, if you want to use a form, use the following format

<div id='my_dialog' class='rdlg' style='display:none'>
  <form>
    <div class='rdlg-content'>
        <input type='text' name='login'>
        <input type='text' name='hobby'>
    </div>
    <div class='rdlg-body-buttons'>
        <input type='button' value='Cancel'>
        <input type='submit' value='OK'>
    </div>
  </form>
</div>


// Finally, you NEED the following js codes to setup rdlg.

<%= javascript_tag  %{

// initialize rdlg with title , width, height
rdlg_setup('my_dialog', 'Add Videos', 400, 480);

// initialize your rdlg as a popup (don't change 'draghandle' and 'closebox' option)
new Popup('my_dialog', 'opener', { modal:true,
                                   duration:1,
                                   draghandle:'rdlg-hdr-center',
                                   closebox:'rdlg-close'
                                 });
} %>
*/


/*
 * Initialize and setup rdlg.
 *
 * Example:
 *    rdlg_setup('my_rdlg', 'hello world', 100, 200);
 */
function rdlg_create(rdlg, title, width )
{
  _rdlg_construct(rdlg);
  rdlg_config(rdlg, title, width);
}


function rdlg_config(rdlg, title, width)
{
  if(title) $$('#'+rdlg+' div.rdlg-hdr-center h1')[0].innerHTML = title;
  if(width) $(rdlg).setStyle({width: width+'px'});
}

/* 
 * (internal function which is used by rdlg_setup)
 *
 * Add frames and header parts to the rdlg
 *
 */
function _rdlg_construct(rdlg)
{
  var part1 = "<div class='rdlg-header rdlg-hdr-left'> <div class='rdlg-hdr-right'> <div class='rdlg-hdr-center'> <h1> Hello </h1> <div id='rdlg-close' class='rdlg-hdr-control rdlg-close'> </div> </div> </div> </div> <div class='rdlg-body rdlg-body-left'> <div class='rdlg-body-right'><div class='rdlg-body-center'><div id='" + rdlg + "-rdlg-content' class='rdlg-content'>";

  var part2 = "</div></div></div></div>"

  $(rdlg).innerHTML = part1 + ' ' + $(rdlg).innerHTML + ' ' + part2;
}
